package hu.monitor.agent.remoting;

import hu.monitor.remoting.InvocationProxyFactory;

import org.springframework.beans.factory.FactoryBean;

public class InvocationProxyFactoryBean<T> implements FactoryBean<T>{
	private final InvocationProxyFactory proxyFactory;
	private T cachedInstance;

	public InvocationProxyFactoryBean(final InvocationProxyFactory proxyFactory) {
		this.proxyFactory = proxyFactory;
	}

	@Override
	public T getObject() throws Exception {
		if (this.cachedInstance == null) {
			this.cachedInstance = this.proxyFactory.newProxy();
		}

		return this.cachedInstance;
	}

	@Override
	public Class<?> getObjectType() {
		return this.proxyFactory.getBeanInterface();
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

}
